package com.ruoyi.driver.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.driver.domain.BankAccounts;
import com.ruoyi.driver.service.IBankAccountsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 银行账号Controller
 * 
 * @author yyj
 * @date 2025-08-17
 */
@RestController
@RequestMapping("/accounts")
public class BankAccountsController extends BaseController
{
    @Autowired
    private IBankAccountsService bankAccountsService;

    /**
     * 查询银行账号列表
     */
    @RequiresPermissions("driver:accounts:list")
    @GetMapping("/list")
    public TableDataInfo list(BankAccounts bankAccounts)
    {
        startPage();
        List<BankAccounts> list = bankAccountsService.selectBankAccountsList(bankAccounts);
        return getDataTable(list);
    }

    /**
     * 导出银行账号列表
     */
    @RequiresPermissions("driver:accounts:export")
    @Log(title = "银行账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BankAccounts bankAccounts)
    {
        List<BankAccounts> list = bankAccountsService.selectBankAccountsList(bankAccounts);
        ExcelUtil<BankAccounts> util = new ExcelUtil<BankAccounts>(BankAccounts.class);
        util.exportExcel(response, list, "银行账号数据");
    }

    /**
     * 获取银行账号详细信息
     */
    @RequiresPermissions("driver:accounts:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bankAccountsService.selectBankAccountsById(id));
    }

    /**
     * 新增银行账号
     */
    @RequiresPermissions("driver:accounts:add")
    @Log(title = "银行账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BankAccounts bankAccounts)
    {
        return toAjax(bankAccountsService.insertBankAccounts(bankAccounts));
    }

    /**
     * 修改银行账号
     */
    @RequiresPermissions("driver:accounts:edit")
    @Log(title = "银行账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BankAccounts bankAccounts)
    {
        return toAjax(bankAccountsService.updateBankAccounts(bankAccounts));
    }

    /**
     * 删除银行账号
     */
    @RequiresPermissions("driver:accounts:remove")
    @Log(title = "银行账号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bankAccountsService.deleteBankAccountsByIds(ids));
    }
}
